package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2022/11/14 16:16
 * @description 693. 交替位二进制数
 */
public class Test693 {
    public static void main(String[] args) {
        System.out.println(hasAlternatingBits(7));
    }

    public static boolean hasAlternatingBits(int n) {
        int i = -1;
        while (n != 0) {
            int temp = n & 1;
            if (temp == i) {
                return false;
            }
            i = temp;
            n >>= 1;
        }
        return true;

    }


    public boolean hasAlternatingBits2(int n) {
        int a = n ^ (n >> 1);
        return (a & (a + 1)) == 0;
    }


}
